package com.d.ui.view.progress;


import com.d.lib.ui.view.progress.CircleProgressBar;
import com.d.ui.view.ResourceTable;
import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.LayoutScatter;
import ohos.app.Context;

/**
 * CircleProgressTest
 * Created by D on 2017/11/1.
 */
public class CircleProgressLayout extends DirectionalLayout {

  public CircleProgressLayout(Context context) {
    super(context);
    init(context);
  }

  public CircleProgressLayout(Context context, AttrSet attrs) {
    super(context, attrs);
    init(context);
  }

  public CircleProgressLayout(Context context, AttrSet attrs, String defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init(context);
  }

  private void init(Context context) {
    Component view =
        LayoutScatter.getInstance(context).parse(ResourceTable.Layout_layout_progress_circle,
            this, true);
    bindView();
  }

  private void bindView() {
    final CircleProgressBar[] cpbCircles = new CircleProgressBar[]{
        (CircleProgressBar) findComponentById(ResourceTable.Id_cpb_progress_progress),
        (CircleProgressBar) findComponentById(ResourceTable.Id_cpb_progress_pending),
        (CircleProgressBar) findComponentById(ResourceTable.Id_cpb_progress_error)};
    cpbCircles[0].setState(CircleProgressBar.STATE_PROGRESS).progress(0.36f);
    cpbCircles[1].setState(CircleProgressBar.STATE_PENDING);
    cpbCircles[2].setState(CircleProgressBar.STATE_ERROR);
    cpbCircles[1].setOnClickListener(new CircleProgressBar.OnClickListener() {
      @Override
      public void onRestart() {
        cpbCircles[1].setState(CircleProgressBar.STATE_PROGRESS).progress(0.36f);
      }

      @Override
      public void onResume() {
        cpbCircles[1].setState(CircleProgressBar.STATE_PROGRESS);
      }

      @Override
      public void onPause() {
        cpbCircles[1].setState(CircleProgressBar.STATE_PENDING);
      }
    });
    cpbCircles[2].setOnClickListener(new CircleProgressBar.OnClickListener() {
      public void onRestart() {
        cpbCircles[2].setState(CircleProgressBar.STATE_PROGRESS).progress(0.36f);
      }

      @Override
      public void onResume() {
        cpbCircles[2].setState(CircleProgressBar.STATE_PROGRESS);
      }

      @Override
      public void onPause() {
        cpbCircles[2].setState(CircleProgressBar.STATE_PENDING);
      }
    });
  }
}
